#ifndef YOOHOO_XMPPCORE_H
#define YOOHOO_XMPPCORE_H

#include "xmppcore/export.h"

#include <QtCore/QString>
#include <QtCore/QList>

namespace yoohoo_xmppcore {

class YOOHOO_XMPPCORE_EXPORT XmppXmlParser {

public:
	XmppXmlParser();
	QList<QString> parse(QString& dataReceived);
	void setDebug(bool debug);
	bool debug();

private:
	enum ParsingStatus {
		FindNextToken,
		StartXmlDocDecl,
		EndXmlDocDecl,
		OpenStream,
		CloseStream,
		StartTag,
		EndTagName,
		EndTag,
		StartCData,
		Error
	};

	bool isCDataStart(QString&, int&);
	bool isXmlDocDeclStart(QString&, int&);
	bool isXmlDocDeclEnd(QString&, int&);
	void elementFound(QString&, int&, QList<QString>&);
	bool findNextToken(QString&, int&);
	bool isTagEnd(QString&, int&);
	bool isCloseStreamStart(QString&, int&);

private:
	bool _debug;

	static const QChar* FLAG_START_ELEMENT;
	static const QChar* FLAG_END_TAG;
	static const QString FLAG_END_ELEMENT;
	static const QString FLAG_EMPTY_ELEMENT_END_TAG;
	static const QString FLAG_START_CDATA;
	static const QString FLAG_END_CDATA;
	static const QString FLAG_START_XML_DOC_DECL;
	static const QString FLAG_END_XML_DOC_DECL;
	static const QChar* FLAG_START_ATTRIBUTE_VALUE;
	static const QString STREAM_TAG_NAME;

};

}

#endif
